"XML转换并发送

FUNCTION ZFM_MM_SYS_PROJECT_TASK.
************************************************
*本地接口
*EXPORTING
*REFERENCE(OUT_TYPE) TYPE CHAR1
*REFERENCE(MSG) TYPESTRING
*TABLES
*DATA TYPE ZPDMR02ST
************************************************
DATA LO_SYS_EXCEPTION TYPE REF TO CX_AI_SYSTEM_FAULT.
DATA: LO_PROXY TYPE REF TO ZPDM_CO_pROJECT_WEB_SERVICE.

DATA: L_REQUEST TYPE ZPDM_SYS_PEOJECT_TASK1,
L_RESPONSE TYPE ZPDM_SYS_PORJECT_TASK_RESPONSE1.

DATA L_ERRTXT TYPE STRING.
DATA TEXT TYPE STRING,
XTEXT TYPE XSTRING,
LO_OREF TYPE REF TO CX_ST_ERROR,
MESSAGE TYPE CHAR200.

DATA: O_OUTPUT TYPE STRING.

TRY.
    CALL TRANSFORMATION ZPDMR02ST
    SOURCE P0HEADER = DATA[]
    RESULT XML XTEXT.

    CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
    EXPORTING
    IM_XSTRING = XTEXT
    IM_ENCODING = 'UTF-8'
    IMPORTING
    EX_STRING = TEXT.

    CATCH CX_ST_ERROR INTO LO_OREF.
        MESSAGE = LO_OREF->GET_TEXT().  
ENDTRY.

L_REQUEST-PARAMETERS-XMLSTR = TEXT.

CREATE OBJECT LO_PROXY
EXPORTING
LOGICAL_PORT_NAME = 'ZPDM01'.

TRY.
    CALL METHOD LO_PROXY->SYS_PEOJECT_TASK
    EXPORTING
    SYS_PROJECT_TASK = L_REQUEST
    IMPORTING
    SYS_PROJECT_TASK_RESPONSE = L_RESPONSE.

    CATCH CX_AI_SYSTEM_FAULT INTO LO_SYS_EXCEPTION.
    L_ERRTXT = LO_SYS_EXCEPTION->ERRORTEXT.
ENDTRY.

IF L_ERRTXT IS NOT INITIAL.
OUT_TYPE = 'E'.
O_OUTPUT = L_ERRTXT.
ELSE.
    OUT_TYPE = 'S'.
    O_OUTPUT = L_RESPONSE-PARAMETERS-RETURN-MESSAGE.
ENDIF.

READ TABLE DATA INDEX 1 ASSIGNING FIELD-SYMBOL(<FS>).
IF SY-SUBRC = 0.
    CALL FUNCTION 'ZFM_SET_LOG'
    EXPORTING
    I_UUID = <FS>-CIDP_TASK_UUID
    I_FS = 'I'
    I_ZSYS = 'MM'
    I_TIP1 = TEXT
    I_TIP2 = O_OUTPUT
    I_NAME = 'ZPDM02'
    I_BWGS = '1'.
ENDIF.

DATA:OS1 TYPE STRING,
OS2 TYPE STRING,
OS3 TYPE STRING,
INT TYPE I.

IF L_RESPONSE-PARAMETERS-RETURN-MESSAGE IS NOT INITIAL.
    SPLIT L_RESPONSE-PARAMETERS-RETURN-MESSAGE AT 'MESSAGE' INTO OS1 OS2 OS3.
    INT = STRLEN( OS2 ) - 3.
    MSG = OS2+1(INT).

DATA: LCO_XML TYPE REF TO CL_XML_DOCUMENT.

CREATE OBJECT LCO_XML.

DATA: TCODEPAGE TYPE CPCODEPAGE.

CALL FUNCTION 'NLS_GET_FRONTEND_CP'
EXPORTING
LANGU = SY-LANGU
FETYPE  'MS'
IMPORTING
FRONTEND_CODEPAGE = TCODEPAGE
EXCEPTIONS
ILLEGAL_SYST_CODEPAGE = 1
NO_FRONTEND_CP_FOUND = 2
INTERNAL_OR_DB_ERROR = 3
OTHERS = 4.

CALL FUNCTION 'SCP_REPLACE_STRANGE_CHARS'
EXPORTING
INTEXT = L_RESPONSE-PARAMETERS-RETURN-MESSAGE
INTER_CP = TCODEPAGE
REPLACEMENT = 32
IMPORTING
OUTTEXT = L-L_RESPONSE-PARAMETERS-RETURN-MESSAGE
EXCEPTIONS
INVALID_CODEPAGE = 1
CODEPAGE_MISMATCH = 2
INTERNAL_ERROR = 3
CANNOT_CONVERT = 4
FIELDS_NOT_TYPE_C = 5
OTHERS = 6.

CLEAR G_RES.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = L_RESPONSE-PARAMETERS-RETURN-MESSAGE
IMPORTING
FAILED = 1
OTHERS = 2.

REFRESH: GT_ITAB,BAPIRET2.

CALL FUNCTION 'SMUM_XML_PARSE'
EXPORTING
XML_INPUT = G_RES
TABLES
XML_TABLE = GT_ITAB
RETURN = GT_BAPIRET2.

DATA: GS_LOG TYPE ZPDMT02.

LOOP AT GT_ITAB ASSIGNING FIELD-SYMBOL(<FS_ITAB>).
    CONDENSE <FS_ITAB>-CNAME NO-GAPS.
    CONDENSE <FS_ITAB>-CVALUE NO-GAPS.
    TRANSLATE <FS_ITAB>-CNAME TO UPPER CASE.

    CASE<FS_ITAB>-CNAME.
        WHEN'TASK_ID'.
            GS_LOG-TASK_ID = <FS_ITAB>-CVALUE.
        WHEN 'TYPE'.
            GS_LOG-TYPE = <FS_ITAB>-CVALUE.
        WHEN 'RESPONSE'.
            GS_LOG-RESPONSE = <FS_ITAB>-CVALUE.
    ENDCASE.

    IF GS_LOG-TASK_ID IS NOT INITIAL AND GS_LOG-TYPE IS NOT INITIAL AND GS_LOG-RESPONSE IS NOT INITIAL.
    MODIFY ZPDMT02 FROM GS_LOG.
    CLEAR GS_LOG.        
    ENDIF.
ENDLOOP.

ENDIF.

ENDFUNCTION.